package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RecordArchive;
import com.ruoyi.system.service.IRecordArchiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 案卷信息Controller
 *
 * @author admin
 * @date 2022-02-21
 */
@RestController
@RequestMapping("/system/archive")
public class RecordArchiveController extends BaseController {
    @Autowired
    private IRecordArchiveService recordArchiveService;

    /**
     * 查询案卷信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:archive:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordArchive recordArchive) {
        startPage();
        List<RecordArchive> list = recordArchiveService.selectRecordArchiveList(recordArchive);
        return getDataTable(list);
    }

    /**
     * 导出案卷信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:archive:export')")
    @Log(title = "案卷信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordArchive recordArchive) {
        List<RecordArchive> list = recordArchiveService.selectRecordArchiveList(recordArchive);
        ExcelUtil<RecordArchive> util = new ExcelUtil<RecordArchive>(RecordArchive.class);
        util.exportExcel(response, list, "案卷信息数据");
    }

    /**
     * 获取案卷信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:archive:query')")
    @GetMapping(value = "/{archiveId}")
    public AjaxResult getInfo(@PathVariable("archiveId") Long archiveId) {
        return AjaxResult.success(recordArchiveService.selectRecordArchiveByArchiveId(archiveId));
    }

    /**
     * 新增案卷信息
     */
    @PreAuthorize("@ss.hasPermi('system:archive:add')")
    @Log(title = "案卷信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordArchive recordArchive) {
        return toAjax(recordArchiveService.insertRecordArchive(recordArchive));
    }

    /**
     * 修改案卷信息
     */
    @PreAuthorize("@ss.hasPermi('system:archive:edit')")
    @Log(title = "案卷信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordArchive recordArchive) {
        return toAjax(recordArchiveService.updateRecordArchive(recordArchive));
    }

    /**
     * 删除案卷信息
     */
    @PreAuthorize("@ss.hasPermi('system:archive:remove')")
    @Log(title = "案卷信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{archiveIds}")
    public AjaxResult remove(@PathVariable Long[] archiveIds) {
        return toAjax(recordArchiveService.deleteRecordArchiveByArchiveIds(archiveIds));
    }
}
